package com.xwrite.toolkit;

import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.XmlSerializerUtil;

import javax.annotation.Nullable;

public class AppSettingsStorage {
    private static final String KEY_FLUTTER_HOME = "FLUTTER_HOME";
    private static final String KEY_DELETE_CONFLICTING_OUTPUTS = "DELETE_CONFLICTING_OUTPUTS";

    private final PropertiesComponent properties;
    public AppSettingsStorage(Project project){
        properties = PropertiesComponent.getInstance(project);
    }

    public void set(AppSettingsState state){
        properties.setValue(KEY_FLUTTER_HOME, state.flutterSdkPath);
        properties.setValue(KEY_DELETE_CONFLICTING_OUTPUTS, state.isDeleteConflictingOutputs);
    }

    public AppSettingsState get(){
        AppSettingsState state = new AppSettingsState();
        state.flutterSdkPath = properties.getValue(KEY_FLUTTER_HOME, "");
        state.isDeleteConflictingOutputs =  properties.getBoolean(KEY_DELETE_CONFLICTING_OUTPUTS, false);
        return state;
    }
}
